﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace MainThreadMoudle
{
    public class ThreadList
    {
        private SortedList<string, ThreadBase> dictionary;

        public int Count => dictionary.Count;
        public ThreadBase this[int index] => dictionary.Values[index];

        public ThreadBase GetThreadByID(string id)
        {
            return dictionary[id];
        }

        public void Add(ThreadBase instance)
        {
            var id = instance.ID;

            if (id == null)
                Debug.LogError("没有正确设置进程的ID！");

            dictionary.Add(id, instance);
        }

        public void PauseList()
        {
            for (int i = 0; i < dictionary.Count; i++)
            {
                var selection = dictionary.Values[i];
                selection.IsEnable = false;
            }
        }

        public void PlayList()
        {
            for (int i = 0; i < dictionary.Count; i++)
            {
                var selection = dictionary.Values[i];
                selection.IsEnable = true;
            }
        }

        public void Start()
        {
            for (int i = 0; i < dictionary.Count; i++)
            {
                var selection = dictionary.Values[i];
                selection.Start();
            }
        }

        public void Update()
        {
            for (int i = 0; i < dictionary.Count; i++)
            {
                var selection = dictionary.Values[i];
                selection.Update();
            }
        }



        public ThreadList()
        {
            dictionary = new SortedList<string, ThreadBase>();
        }
    }
}